const fs = require("fs");

exports.uploadFile = async (file) => {
  const { filepath, originalFilename } = file;

  if (!filepath || !originalFilename) {
    throw new Error("Invalid file");
  }

  const reader = fs.createReadStream(filepath);
  const upStream = fs.createWriteStream(`assets/${originalFilename}`);

  reader.pipe(upStream);

  return { message: "Upload success!", fileName: originalFilename };
};
